<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />
<title>隐患列表</title>
<link rel="stylesheet" href="../../css/s_plus.css" />
<link rel="stylesheet" href="../../css/base.css" />
<link rel="stylesheet" href="../../css/layout.css" />
<link rel="stylesheet" href="../../css/choice.css" />
<script type="text/javascript" src="../../libs/vue.js" ></script>
<script type="text/javascript" src="../../js/jquery.1.9.1.min.js" ></script>
<script type="text/javascript" src="../../js/app/url.js" ></script>
<script type="text/javascript" src="../../libs/hui.js" ></script>
<script type="text/javascript" src="../../js/s_plus.js" ></script>
<script type="text/javascript" src="../../js/md5.js"></script>
<script type="text/javascript" src="../../js/app/api.js"></script>
<script type="text/javascript" src="../../js/control/mescroll/mescroll.min.js"></script>
<link rel="stylesheet" href="../../js/control/mescroll/mescroll.min.css" />
	<script type="text/javascript" src="../../js/control/select/iosSelect.js"></script>
		<link rel="stylesheet" href="../../js/control/select/iosSelect.css" />
<style>
	/*列表*/
			.mescroll{
				position: fixed;
				top: 160px;
				bottom: 0;
				height: auto;
			}
			
			/*隐藏百度地图 底部LOGO*/
			.BMap_cpyCtrl {
				display: none;
			}
			
			.anchorBL {
				display: none;
			}
		
</style>
</head>
<body>
	
<div id="wrapper">
		

<header class="f_l maxbox subhead">
 <a class="back" @click="back"><i class="iconfont">&#xe605;</i></a>
  <h1>隐患列表</h1>
 <a class="f_r arrow_r" @click="gisMap"><i class="iconfont">&#xe611;</i></a>

</header>

<section class="f_l maxbox risk ">
  <dl>
    <dt>
    
    </dt>
    
    <dd>
    <a @click="add">十 上传隐患</a>

    </dd>
  </dl>
</section>
	<section class="f_l maxbox edit_list">
				<ul>
					<li>
						<b>区域</b>
						<p>

						<select @change="check" v-model="areaId"><option value="ccf6eb06b1fb4b259e53636cd57a7f08">天心区</option><option value="0cf7295e308e4195a394b64130404fec">宁乡县</option><option value="ff0aff68a1cd4f598a03dc6bd374812e">岳麓区</option><option value="5f4d95cdcdf74090b6c9a85386f1edc2">开福区</option><option value="7d842a96ad8f468792eff00988639751">望城区</option><option value="51b8b84ba2f84a95a7651e80206e2ed1">芙蓉区</option><option value="830eaa62023c4110ac7af62800059027">长沙县</option><option value="af7c16f4efb74f3d997aa0a76284516a">雨花区</option></select>
						</p>
					</li>
					
					<!--<li>
						<b>时间</b>
						<p>
							<input id="xcTime" class="edit_txt" readonly="readonly" v-model="time" name="" type="text" placeholder="请选择时间">
						</p>
					</li>-->
					
					</ul>
</section>


	<div id="myscroll" class="mescroll">

<section class="f_l maxbox risk_list">
	
  <ul>
    <li v-for="item in lists">
      <a @click="detail(item.id)">
        <b>{{item.content}}</b>
        <p>{{showState(item.state)}}</p>
        <em>{{item.startDate}}</em>
      </a>
    </li>
    <!--<li>
      <a href="risk_show.html">
        <b>芙蓉区朝阳街</b>
        <p>详细描述马路上井盖丢失</p>
        <em>2018/09/11 15:30</em>
      </a>
    </li>
    <li>
      <a href="risk_show.html">
        <b>芙蓉区朝阳街</b>
        <p>详细描述马路上井盖丢失</p>
        <em>2018/09/11 15:30</em>
      </a>
    </li>
    <li>
      <a href="risk_show.html">
        <b>芙蓉区朝阳街</b>
        <p>详细描述马路上井盖丢失</p>
        <em>2018/09/11 15:30</em>
      </a>
    </li>-->
  </ul>
</section>
    <div id="no_data"></div>

</div>
</div>
<script>


    	var sp = new Vue({
				el:"#wrapper",
				data:{
					time:"",
					areaId:"af7c16f4efb74f3d997aa0a76284516a",
					startTime:"",
					endTime:"",
					lists:[]
			
				},
					methods:{
						check:function(){
							var page = {num:1,size:10,time:null};
							refreshData(page);
						},
						back:function(){
					hui.open("inspection.html?time"+apiManage.getNow(), {}, true, {});	

					},
					add:function(){
								var timestamp=new Date().getTime();
								hui.open("risk_add.html?date="+timestamp, {}, true, {});
					},
						
					detail:function(pid){
							localStorage.setItem("pid",pid);
							hui.open("risk_show.html?time"+apiManage.getNow(), {}, true, {});	

						},
					
						
						geshi:function(param){
							return formatTime(param);
						},
						
						showState:function(param){
//								0下发 1接收 2处理
							if(param=='0'){
								return "下发";
							}
							else if(param=='1'){
								return "接收";
							}
							else{
								return "处理";

							}
						},
						gisMap:function(){
							hui.open("risk_map.html?t="+apiManage.getNow());
						}
						
					
				
					}
					,
		mounted: function() {
			
//				var view = hui.create('risk_map.html',{},true,{name:'hcoder', age:'3.0'});

			
			var nowdate = new Date();
	        var y = nowdate.getFullYear();
	        var m = nowdate.getMonth()+1;
	        var d = nowdate.getDate();
	        var formatnowdate1 = y+'-'+m+'-'+d;
	        this.endTime=formatnowdate1+" 23:59:59";
	         console.log(formatnowdate1);
	
	        //获取系统前一个月的时间
	        nowdate.setMonth(nowdate.getMonth()-1);
	        var y = nowdate.getFullYear();
	        var m = nowdate.getMonth()+1;
	        var d = nowdate.getDate();
	        var formatwdate2 = y+'-'+m+'-'+d;
            this.startTime=formatwdate2+" 00:00:00";
        	console.log(formatwdate2);
			
			//创建MeScroll对象,down可以不用配置,因为内部已默认开启下拉刷新,重置列表数据为第一页
			//解析: 下拉回调默认调用mescroll.resetUpScroll(); 而resetUpScroll会将page.num=1,再执行up.callback,从而实现刷新列表数据为第一页;
			var self = this;
			self.mescroll = new MeScroll("myscroll", { //请至少在vue的mounted生命周期初始化mescroll,以确保您配置的id能够被找到
				up: {
					auto : true,
					callback: refreshData,
					isBounce: false,
					empty: {
						warpId: "no_data",							
						tip: "-------暂无数据-------"
					},
				}
			});

		}
		
		
		
				});
				
				
				function refreshData(page){
					
					console.log("page params-----"+JSON.stringify(page));
						
					var path = urlManager.getCheckTrouble();
				  	var username=	localStorage.getItem("username");
					var sec= localStorage.getItem("sec_pwd");
				  	var time = apiManage.getNow();
				  	var key = "loginName="+username+"&passWord="+sec+"&time="+time;
				  	var paramKey=hex_md5(key);
				  	var jsonParam = JSON.stringify({loginName:username,time:time,key:paramKey});
				  	console.log(jsonParam);
					
					var params= {areaId:sp.areaId,startTime:sp.startTime,endTime:sp.endTime,pageNo:page.num,pageSize:10};

                    console.log("params-----"+JSON.stringify(params));
					
						$.ajax({
					         type: "GET",
					         url: path,
					         data:params,
					         beforeSend: function(request) {
					            request.setRequestHeader("loginName",username);
					            request.setRequestHeader("time",time);
					            request.setRequestHeader("sign",paramKey);
					            request.setRequestHeader("Content-Type","application/text");
					
					         },
					         success: function(result) {
					             console.log("隐患列表:"+JSON.stringify(result));
					          		 var datas=result.data;
//					          		if() 
					              if(datas != null) {
										//如果是第一页需手动制空列表 (代替clearId和clearEmptyId的配置)
										if(page.num == 1) {sp.lists = []};
						
//									if(page.num*10>result.dataCount){
//											sp.mescroll.endSuccess(sp.lists.length, true);
//										return;
//											}
										//更新列表数据
										sp.lists = sp.lists.concat(datas);
												
											
													
										if(sp.lists.length<10){
								            sp.mescroll.endSuccess(sp.lists.length, false);
										}
										else{
								            sp.mescroll.endSuccess(sp.lists.length, true);
						
										}
						
										//sp.mescroll.endBySize(sp.lists.length,dataJson.bodyData.totalItems); //必传参数(当前页的数据个数, 总数据量)
									} else{
										sp.lists = null;
										sp.mescroll.endErr();
									}				 
					             
					         }
		     });
					

	}	


 
	        Date.prototype.format = function (format) //author: meizz
	    {
	        var o = {
	            "M+": this.getMonth() + 1, //month
	            "d+": this.getDate(),    //day
	            "h+": this.getHours(),   //hour
	            "m+": this.getMinutes(), //minute
	            "s+": this.getSeconds(), //second
	            "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
	            "S": this.getMilliseconds() //millisecond
	        }
	        if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
	        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	        for (var k in o) if (new RegExp("(" + k + ")").test(format))
	            format = format.replace(RegExp.$1,
	          RegExp.$1.length == 1 ? o[k] :
	            ("00" + o[k]).substr(("" + o[k]).length));
	        return format;
	    }

	    function formatTime(val) {
	    	if(val==null||val==''){
	    		return "";
	    	}
	        var re = /-?\d+/;
	        var m = re.exec(val);
//	         m = m.replace(/\-/g, "/");
	        var d = new Date(parseInt(m[0]));

	        return d.format("yyyy-MM-dd hh:mm:ss");
	    }
	    
	    
	  
	
</script>

</body>
</html>